<template>

	<view class="flowLaunch-v">


		<u-toast ref="uToast"></u-toast><!-- 弹窗 -->
		<!-- 搜索 -->
	<!-- 	<view class="search-box search-box_sticky">
			<u-search placeholder="请输入条码搜索" v-model="keyword" height="72" :show-action="false" @change="search"
				bg-color="#f0f2f6" shape="square">
			</u-search>
		</view> -->
		<!-- 列表 -->
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :sticky="true"
			:down="downOption" :up="upOption" style="z-index: -1;position: absolute;width: 100%;background-color: #f0f2f6;">

			<view class="flow-list" v-if="list.length > 0">
				<view class="flow-list-box">
					<uni-swipe-action ref="swipeAction">
						<uni-swipe-action-item v-for="(item, index) in list" :key="item.id" :threshold="0"
							class="data-item">
							<view class="item" :id="'item'+index" ref="mydom" style="height: 140px;">


								<view class="item-left">

									<text class="title u-line-1 u-font-28"
										style="font-weight: bold;">部件名：{{item.ComponentName ? item.ComponentName : ''}}</text>
									<text class="title u-line-1 u-font-28" style="font-weight: bold;">数  量：{{item.Qty ? item.Qty : ''}}{{item.Unit ? item.Unit : ''}}</text>
									<text class="title u-line-1 u-font-26"
										style="font-weight: bold;">扫描人：{{item.ScanUserId ? item.ScanUserId : ''}}</text>
									<text class="title u-line-1 u-font-26" style="font-weight: bold;">条  码：{{item.Barcode ? item.Barcode : ''}}</text>
									<text class="title u-line-1 u-font-26"
										style="font-weight: bold;">扫描时间：{{item.ScanDate | date('yyyy-mm-dd hh:MM')}}</text>
								</view>
								<view class="item-right">
									<image :src="item.flowStatus" mode="widthFix" class="item-right-img">
									</image>
								</view>
							</view>
						</uni-swipe-action-item>
					</uni-swipe-action>
				</view>
			</view>
		</mescroll-body>
	</view>
</template>
<script>
	import resources from '@/libs/resources.js'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import {
		GetBoxNoCount,
		ScanInterface

	} from '@/api/q1/business/scan/scan.js'
	export default {

		props: {

			No: { // id
				type: String,
				default: ''
			},
			BoxNo: {
				type: String,
				default: '' // edit 编辑 detail 详情
			},
		},

		mixins: [MescrollMixin],
		data() {
			return {
				flowStatus: '',
				downOption: {
					use: true,
					auto: true
				},
				upOption: {
					page: {
						num: 0,
						size: 100,
						time: null
					},
					empty: {
						use: true,
						icon: resources.message.nodata,
						tip: "暂无数据",
						fixed: true,
						top: "300rpx",
					},
					textNoMore: '没有更多数据',
				},
				keyword: '',
				list: [],



			}
		},

		mounted() {

			uni.$on('refreshScan', data => {

				this.list = [];
				this.mescroll.resetUpScroll();

			})


		},
		onUnload() {
			uni.$off('refresh')
		},

		methods: {

			upCallback(page) {
				let query = {
					keyword: this.keyword,
					currentPage: page.num,
					pageSize: page.size,
					No: this.No,
					BoxNo: this.BoxNo
				}
				GetBoxNoCount(query, {
					load: page.num == 1
				}).then(res => {

					this.mescroll.endSuccess(res.data.ScannedCount.length);
					if (page.num == 1) this.list = [];
					const list = res.data.ScannedCount.map(o => ({
						'flowStatus': this.getFlowStatus(o.PrintStatus),
						...o
					}))
					this.list = this.list.concat(list);
				}).catch(() => {
					this.mescroll.endErr();
				})
			},
			getFlowStatus(status) {
				let flowStatus;
				switch (status) {
					case 0: //未打印
						flowStatus = resources.complaintStatus.unprint
						break;
					case 1: //已打印
						flowStatus = resources.complaintStatus.print
						break;
				
					default: //未打印
						flowStatus = resources.complaintStatus.unprint
						break;
				}
				return flowStatus
			},


			search() {

				// 节流,避免输入过快多次请求
				this.searchTimer && clearTimeout(this.searchTimer)
				this.searchTimer = setTimeout(() => {
					this.list = [];
					this.mescroll.resetUpScroll();
				}, 300)
			}

		},



	}
</script>

<style lang="scss" scoped>
	// page {
	// 	background-color: #f0f2f6;
	// }

	@import "@/assets/scss/common.scss";

	page {
		background-color: #f0f2f6;
		height: 100%;
		/* #ifdef MP-ALIPAY */
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		/* #endif */
	}

	.flow-list {
		padding-top: 5px;
		padding-bottom: 5px;
	}

	.flow-list .data-item {
		margin-bottom: 10px;
	}

	.w-100 {
		width: 100rpx;
	}

	.flowLaunch-v {
		width: 100%;

		.flow-list-box {
			width: 95%;

			.item-left-top {
				display: flex;
				width: 100%;

				.common-lable {
					font-size: 24rpx;
					padding: 2rpx 8rpx;
					margin-right: 8rpx;
					border-radius: 8rpx;
					color: #ffffff;
					border: 1px solid #ffffff;
					background-color: #6dcc51;
				}

				.urgent-lable {
					color: #E6A23C;
					border: 1px solid #E6A23C;
					background-color: #fef6e5;
				}

				.important-lable {
					color: #F56C6C;
					border: 1px solid #F56C6C;
					background-color: #fee5e5;
				}

				.title {
					width: unset;
					flex: 1;
					min-width: 0;
				}
			}
		}
	}
</style>